package cn.xmy.demo01.servlet;

import cn.xmy.demo01.service.TrolleyDaoService;
import cn.xmy.demo01.service.impl.TrolleyDaoImplService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/updateZhiId")
public class UpdateZhiId extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        TrolleyDaoService trolleyDaoService=new TrolleyDaoImplService();
        String zhiId=request.getParameter("zhiId");
        int trolley=0;
        try {
            trolley=trolleyDaoService.updateZhiId(zhiId);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        if (trolley>0){
            request.getRequestDispatcher("zhiId").forward(request, response);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}